package p.ithorns.integration.zk.common;

import lombok.extern.slf4j.Slf4j;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;

import java.util.concurrent.CountDownLatch;

/**
 * DefaultWatcher
 * TODO
 *
 * @author ithorns
 * @version 1.0
 * @date 2019/9/21 22:15
 */
@Slf4j
public class DefaultWatcher implements Watcher {

    private CountDownLatch cdl;

    public void setCdl(CountDownLatch cdl) {
        this.cdl = cdl;
    }

    @Override
    public void process(WatchedEvent event) {
        Event.KeeperState state = event.getState();
        switch (state) {
            case SyncConnected:
                log.info("DefaultWatcher ===========> Zk connected!");
                this.cdl.countDown();
                break;
            default:
                break;
        }

    }
}
